package server.core.manager;

import server.core.base.Flight;
import server.core.base.Ticket;
import server.core.base.User;
import server.core.dao.DaoFactory;
import server.core.dao.DaoFactory.daoType;

public class Customer extends Guest {
	public Customer(daoType type) {
		super(type);
	}

	/**
	 * Add several tickets to data-base
	 * 
	 * @param flight
	 * @param price
	 * @param n
	 * @return
	 */
	public boolean makeSeveralTikets(Flight flight,
			Ticket.TicketClass ticketClass, float price, int n) {
		for (int i = 0; i <= n; i++)
			DaoFactory.getDao(typeOfDao).saveObject(
					new Ticket(flight, ticketClass, price));
		return true;
	}

	/**
	 * @param idTicket
	 * @param idCustomer
	 * @return
	 */
	public long reserveTicket(Ticket ticket, User user) {
		if (ticket.isAvailability()) {
			ticket.setCustomer(user);
			ticket.setAvailability(false);
			return DaoFactory.getDao(typeOfDao).saveObject(ticket);
		} else
			return 0;
	}

	public long cancelTicket(Ticket ticket) {
		if (!ticket.isAvailability()) {
			ticket.setCustomer(null);
			ticket.setAvailability(true);
			return DaoFactory.getDao(typeOfDao).saveObject(ticket);
		} else
			return 0;
	}

}
